//
//  ACAssetsGridViewController.m
//  AlbumFetch
//
//  Created by 黄志明 on 2017/2/6.
//  Copyright © 2017年 黄志明. All rights reserved.
//

#import "ACAssetsGridViewController.h"
#import "ACAssetCell.h"
#import "ACAssetAccessManager.h"
#import "ACAssetsPickerController.h"

@interface ACAssetsGridViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>

@property (nonatomic, strong) UICollectionView *assetCollectionView;
@property (nonatomic, strong) NSArray <ACAssetModel *> * dataSource;

@end

@implementation ACAssetsGridViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

#pragma mark - Scroll to Botton

- (void)scrollToBottomIfNeeded
{
    if (_dataSource.count > 0)
    {
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_dataSource.count - 1 inSection:0];
        [_assetCollectionView scrollToItemAtIndexPath:indexPath
                                     atScrollPosition:UICollectionViewScrollPositionBottom
                                             animated:NO];
    }
}

#pragma mark - UICollectionViewDelegate, UICollectionViewDataSource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _dataSource.count + 1;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return nil;
}

#pragma mark - Getter

- (ACAssetsPickerController *)containerViewController
{
    return (ACAssetsPickerController *)self.navigationController;
}

- (ACAssetMediaType)fetchAssetMediaType
{
    ACAssetMediaType mediaType;
    
    if ([self containerViewController].allowPickPhoto)
    {
        mediaType = mediaType | ACAssetMediaTypePhoto;
    }
    
    if ([self containerViewController].allowPickVideo)
    {
        mediaType = mediaType | ACAssetMediaTypeVideo;
    }
    
    if ([self containerViewController].allowPickAudio)
    {
        mediaType = mediaType | ACAssetMediaTypeAudio;
    }
    
    return mediaType;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
